import uuid
from datetime import datetime
from sqlalchemy import (UUID, Column, String, Text, DateTime, text, func)
from extensions import db


class App(db.Model):
    __tablename__ = 'apps'
    id = Column(UUID, primary_key=True, nullable=False, server_default="uuid_generate_v4()")
    user_id = Column(UUID, nullable=False, comment="用户 id")
    name = Column(String(255), nullable=False, server_default=text("''::character varying"), comment="名字")
    icon = Column(String(255), nullable=False, server_default=text("''::character varying"), comment="图标")
    description = Column(Text, nullable=False, server_default=text("''::text"), comment="描述")
    created_at = Column(DateTime, nullable=False, server_default=text("current_timestamp(0)"), comment="创建时间")
    update_date = Column(
        DateTime,
        nullable=False,
        server_default=func.current_timestamp(),
        server_onupdate=func.current_timestamp(),
        comment="更新时间"
    )
